﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Zarion_Quest.Base
{
    /// <summary>
    /// Classe abstrata que serve de base para criação de inimigos
    /// </summary>
    class Enemy : Object2D
    //LEMBRAR DE RECOLAR ABSTRATA< MAS COLOCAR AS DERIVADAS
    {
        public Enemy(Texture2D texture)
            : base(texture)
        {
            current_animation.frame.Width = 72;
            current_animation.current_frame = 2;
            current_animation.frame.X = current_animation.frame.Width *
                                            current_animation.current_frame;
        }


        /// <summary>
        /// Método para mover o inimigo pelo eixo X
        /// </summary>
        /// <param name="X"></param>
        public void moveByX(float X)
        {

            if (X > 0)
            {
                Animate(1);
                if (Position.X - current_animation.frame.Width*4.75f< Game1.Self.Window.ClientBounds.X)
                {
                    Position = new Vector2(Position.X + X, Position.Y);
                }
            }
            if (X < 0)
            {
                Animate(-1);
                if (Position.X - current_animation.frame.Width *2.5f > 0)
                {
                    Position = new Vector2(Position.X + X, Position.Y);
                }
            }

        }

        /// <summary>
        /// Método para mover o inimigo pelo eixo Y
        /// </summary>
        /// <param name="Y"></param>
        public void moveByY(float Y)
        {
            Position = new Vector2(Position.X, Position.Y + Y);
        }


        /// <summary>
        /// Animates the object according to the number given
        /// </summary>
        /// <param name="X">negative will make it move left, positive will move it right 0 will make it go to the default look</param>
        public void Animate(float X)
        {
            if (X >= 1)
            {
                if (current_animation.current_frame < 4)
                {
                    current_animation.current_frame++;
                    current_animation.active = true;
                }

            }
            else if (X <= -1)
            {
                if (current_animation.current_frame > 0)
                {
                    current_animation.current_frame--;
                    current_animation.active = true;
                }
            }
            else
            {
                current_animation.active = false;
            }

            if (current_animation.active == false)
            {
                if (current_animation.current_frame > 2)
                {
                    current_animation.current_frame--;
                }
                else if (current_animation.current_frame < 2)
                {
                    current_animation.current_frame++;
                }
            }

            current_animation.frame.X = current_animation.frame.Width *
                                            current_animation.current_frame;
        }
    }
}
